#include "MysqlConn.h"

MysqlConn::MysqlConn()
{
	//加载驱动
	driver = sql::mysql::get_driver_instance();
}

MysqlConn::~MysqlConn()
{
	conn->close();
}


bool MysqlConn::Connect(string ip, string user, string passwd, string db)
{	
	//建立连接
	conn = (Connection*)driver->connect(ip,user,passwd);
	conn->setSchema(db);
	if (!conn) {
		return false;
	}
	return true;
}


Connection* MysqlConn::getConn() const
{
    return conn;
}

void MysqlConn::refreshAliveTime()
{
	m_alivetime = steady_clock::now();//拿到当前时间
}

long long MysqlConn::getAliveTime()
{
	nanoseconds res = steady_clock::now() - m_alivetime;
	milliseconds millsec = duration_cast<milliseconds>(res);
	return millsec.count();
}

